<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>支付宝</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    .body-all {
      width: 100%;
      height: 100%;
      background-color: #f5f5f5;
    }
    .img-top {
      text-align: center;
      background-color: white;
    }
    .content {
      margin-top: 40px;
    }
    p {
      color: red;
      font-weight: 700;
      font-size: 20px;
      line-height: 20px;
    }
    .mp {
      line-height: 35px;
    }
    .mp2 {
      font-weight: 400;
      font-size: 16px;
      color: #a8a8a8;
    }
    #scan {
      width: 90%;
      height: 45px;
      margin-left: 5%;
      margin-top: 30px;
      border: 1px solid white;
      background-color: #00abee;
      text-align: center;
      font-size: 18px;
      line-height: 45px;
      color: #fff;
      cursor: pointer;
    }
    .disable {
      pointer-events: none;
    }
  </style>
</head>
<body>
  <div id="get-url" style="display: none">{{ url }}</div>
  <div class="body-all">
    <div class="img-top">
      <img src="http://image.barchain.net/qr_alipay_3/qr_alipay3_logo_alipay.jpg">
    </div>
    <div class="content">
      <p>
        摄像头弹出后，请直接扫描你身边的任意商品(饮料条形码、香烟、零食等)包装上的条形码或二维码，即可跳转支付界面。
      </p>
      <p class="mp">
        如：饮料上的条形码
      </p>
      <p class="mp">
        如：烟盒上的条形码
      </p>
      <p class="mp">
        如：零食上的条形码
      </p>
      <p class="mp">
        如：纸巾上的条形码
      </p>
      <p class="mp">
        如：其他商品上的条形码或二维码
      </p>
      <p class="mp2">
        如果交易中断！请把支付宝关闭重新打开再支付即可
      </p>
    </div>
    <div id="scan">立即支付</div>
    <!-- <button id="scan">立即支付</button> -->
  </div>

<script src="https://a.alipayobjects.com/amui/zepto/1.1.3/zepto.js"></script>
<script src="https://gw.alipayobjects.com/as/g/h5-lib/alipayjsapi/3.1.1/alipayjsapi.inc.min.js"></script>
<script type="text/javascript">
var url = $("#get-url").text();
$("#scan").on('click', function(){
    // debugger
    console.log(000)
    ap.scan({
        type: 'qr'
    }, function (res) {
        if (res.error == 10) {
            // 错误码为10：用户取消操作
            // ...
        } else if (res.error == 11) {
            // 错误码为11：扫码失败
            alert('网络开小差了...');
            // ....
        } else {
            console.log(res.code);
            // res.code为扫码返回的结果
            window.location = url
        }
    });
})

var num = 0;
// $("#scan").attr("disabled","true");
$("#scan").css('background-color','gray');
$("#scan").addClass('disable');
var t = setInterval(function(){
  num++;
  $("#scan").text('支付宝授权数据加载中' +num+'%');
   if(num==100){
      clearInterval(t);
      $("#scan").removeClass('disable');
      $("#scan").css('background-color','#00abee');
      $("#scan").text('立即支付')
   }
},80);

</script>
</body>
</html>